<?php

	include_once('../sys/sys.php');
	header('Content-Type: text/html; charset=utf-8');
	
	
	
	//获取系统内容以及分页
	
	//获取分类以及分页号
	$st = $_GET['st'];
	$name = trim($_GET['name']);
	if(is_null($st)){$st = 0;}
	//列出的图片数量(注意,不要超过15张)
	$listnum = 60;
	
	$array_piclist = array();
	
	$DB->build_query(array(
			'select' 	=> 'id,name,lastupdate,count',
			'from'		=> '89890tags',
			'order'		=> 'lastupdate DESC',
			'where'		=> 'name like "%' . $name . '%"' ,
			'limit'		=> array($st,$listnum)
	));
	$qid = $DB->exec_query();
	$i = 0;
	while ($row = $DB->fetch_row($qid)) {
		if($row['lastupdate'] <= 0) $row['lastupdate'] = 0;
		$array_piclist[$i]['tagname'] = $row['name'];
		$array_piclist[$i]['id'] = $row['id'];
		$array_piclist[$i]['count'] = $row['count'];
		$array_piclist[$i]['lastupdate'] = get_date_time($row['lastupdate']);
		$array_piclist[$i]['downloadpicslink'] = SITE_URL . '89890/pics.php?action=getpicfiles&tid=' .$row['id'];
		$array_piclist[$i]['picslink'] = SITE_URL . '89890/pics.php?action=getpicurls&tid=' .$row['id'];
		$array_piclist[$i]['getnewlink'] = SITE_URL . '89890/cr.php?tid=' .$row['id'];
		$i++;
	}
	//处理分页信息
	//获取总TAG数
	$totalnumbers = get_count_of_field('89890tags','name like "%' . $name . '%"');
	$pagelink = $Elsesky->PageLinkR($st,$totalnumbers,$listnum,SITE_URL."89890/search.php?name=" . $name . "&st=<:st:>");
	
	//处理最常访问内容
	$ccount = 9;
	$array_ccount = array();
	
	$DB->build_query(array(
			'select' 	=> '*',
			'from'		=> '89890tags',
			'order'		=> 'scount DESC',
			'limit'		=> array(0,$ccount)
	));
	$qid = $DB->exec_query();
	$i = 0;
	while ($row = $DB->fetch_row($qid)) {
		$array_ccount[$i]['tidname'] = $row['name'];
		$array_ccount[$i]['ccount'] = $row['scount'];
		$array_ccount[$i]['tidlink'] = SITE_URL . '89890/search.php?name=' . $row['name'];
		$i++;
	}
	
	
	//初始化模版变量
	$page = init_smart_template_obj('89890/list.html',CACHE_DIR,CACHE_DIR,TEMPLATE_DIR);
	$page->assign("piclist",$array_piclist);
	$page->assign("system",$sysinfo);
	$page->assign("pagelink",$pagelink);
	$page->assign("searchpg",SITE_URL . '89890/search.php');
	$page->assign("title",'搜索"' . $name . '"的结果'); 
	$page->assign("tidlink",$array_ccount);
	$page->assign("ccount",$ccount);
	

	$page->output();
	
?>